/*
 * gpio.c
 * Project 5
 * Nicole Ang (nang1@asu.edu)
 * Bijan Fakhri (bfakhri@asu.edu)
 * CSE 325: Embedded Microprocessor Systems
 * Spring 2013
 */

#include "gpio.h"
#include "support_common.h"
#include <stdio.h>
void gpio_ledArray_init(){
	//This function initializes PORT TH pins 6 and 7
	//These pins correspond to LEDM_STR and LEDM_OE
	//pin 6 - LEDM_STR (posedge triggered)
	//pin 7 - LEDM_OE (active low)
	
	//Port TH pin 6 - set to output
	MCF_GPIO_DDRTH |= MCF_GPIO_DDRTH_DDRTH6;
	//Port TH pin 7 - set to output
	MCF_GPIO_DDRTH |= MCF_GPIO_DDRTH_DDRTH7;
	
	//Port TH pin 6 - set to GPIO function
	MCF_GPIO_PTHPAR &= ~MCF_GPIO_PTHPAR_PTHPAR6(3);
	//Port TH pin 7 - set to GPIO function
	MCF_GPIO_PTHPAR &= ~MCF_GPIO_PTHPAR_PTHPAR7(3);
}

void refreshArray(){
	//Make a posedge
	MCF_GPIO_PORTTH |= MCF_GPIO_PORTTH_PORTTH6; 
	//Wait
	for(int i=0; i<1000000; i++){} 
	
	//Make a negedge
	MCF_GPIO_PORTTH &= ~MCF_GPIO_PORTTH_PORTTH6; 
	printf("refreshed\n"); 
}
void toggleArray(int on){
	if(on)
	{
		MCF_GPIO_PORTTH &= ~MCF_GPIO_PORTTH_PORTTH7;	//Turns array on
	}
	else
	{
		MCF_GPIO_PORTTH |= MCF_GPIO_PORTTH_PORTTH7;		//Turns array on
	}
	for(int i=0; i<10000000; i++){}
	printf("Toggled\n");
}

/* From proj4
void gpio_button_init(){
	//configure port TA pin 0 for primary (GPT) function
	MCF_GPIO_PTAPAR |= MCF_GPIO_PTAPAR_PTAPAR0(1);
	
	//clear DDRT for input
	MCF_GPIO_DDRTA &= ~MCF_GPIO_DDRTA_DDRTA0;
} */